{include file="../application/admin/view/common/header.html" /}


<!--main content start-->
<section class="main-content">


    <!--start page content-->

    <div class="row">

        <div class="col-md-12">
            <div class="panel panel-default collapsed">
                <div class="panel-heading">
                    <label for="name"
                           style="color: #666666;font-size: 16px;font-weight: normal;line-height: 34px;margin: 3px 0;margin-right: 25px;">状态:
                        <select id="select1" style="height: 34px;border:1px solid #e0e0e0;width: 150px; ">
                            <option value="0">全部</option>
                            <option value="1">待处理</option>
                            <option value="2">处理中</option>
                            <option value="3">处理完成</option>
                        </select>
                    </label>
                    <div class="float-m" style="display: inline-block;">
                        <label>日期范围:</label>
                        <input type="text" id="logmin" class="input-text Wdate"
                               style="width:100px;display: inline-block;">
                        -
                        <input type="text" id="logmax" class="input-text Wdate"
                               style="width:100px;display: inline-block;">
                    </div>
                    <div class="search-form">
                        <input type="text" class="form-control" placeholder="搜索用户名/手机/联系人"/>
                        <button type="button" id="submit" class="btn-search"><i class="fa fa-search"></i></button>
                    </div>
                </div>
                <div class="panel-body">

                    <table class="table table-hover table-striped table-bordered" data-page-size="12"
                           data-filter=#filter>
                        <thead>
                        <tr>
                            <th>ID</th>
                            <th>用户名</th>
                            <th>订单编号</th>
                            <th>订单商品</th>
                            <th>问题描述</th>
                            <th>下载</th>
                            <th>联系人</th>
                            <th>手机号码</th>
                            <th>创建时间</th>
                            <th>处理结果</th>
                            <th>状态</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>


                        </tbody>
                    </table>
                    <div class="pager" id="page" style="text-align: right;"></div>
                </div>
            </div>
        </div>
    </div><!--end row-->

    <!--end page content-->
</section>
<!--end main content-->


<!--Common plugins-->
<script src="_JS_/jquery.min.js"></script>
<script src="_JS_/jquery.base64.js"></script>
<script src="_JS_/jquery.cookie.js"></script>
<script src="_JS_/bootstrap.min.js"></script>
<script src="_JS_/jasny-bootstrap.min.js"></script>
<script src="_JS_/jquery.slimscroll.min.js"></script>
<script src="_JS_/jquery.nanoscroller.min.js"></script>
<script src="_JS_/metismenu.min.js"></script>
<script src="_JS_/float-custom.js"></script>
<script type="text/javascript" src="_JS_/layer/layer.js"></script>
<script type="text/javascript" src="_JS_/laypage/laypage.js"></script>
<script type="text/javascript" src="_JS_/laydata/laydate.js"></script>
<script type="text/javascript" src="_JS_/getMyDate.js"></script>
<!-- Page-Level Scripts -->
<script>

    $(function () {
        $("#page-title").html("交易申诉管理");
        postfile(1);
    })

    function postfile(page) {
        var static = $("#select1").val();
        var logmin = $("#logmin").val();
        var logmax = $("#logmax").val();
        var username = $(".search-form input").val();
        $.ajax({
            type: 'GET',
            url: "{:url('api/complain/complain_index')}",
            dataType: 'jsonp',
            jsonp: 'callback',
            data: {'page': page, 'static': static, 'logmin': logmin, 'logmax': logmax, 'username': username},
            beforeSend: function () {
                var index = layer.load(1, {
                    shade: [0.1, '#333333'] //0.1透明度的白色背景
                });
            },
            success: function (msg) {
                layer.closeAll();
                $("#complain_management").addClass("active").children("ul").addClass("in");
                $("#complain_index").addClass("choose");
                if (msg.code == 200) {
                    var pages = Math.ceil(msg.data.count / 10);
                    $(".table tbody").html("");
                    if (msg.data.data.length > 0) {
                        for (var i = 0; i < msg.data.data.length; i++) {
                            var time = msg.data.data[i].time;
                            ltime = getMyDate(time * 1000);

                            var html = '<tr id="' + msg.data.data[i].id + '">';
                            html += '<td>' + msg.data.data[i].id + '</td><td>' + msg.data.data[i].username + '</td>';
                            html += '<td class="order">' + msg.data.data[i].order + '</td><td><img width="100px;" src="/Images/' + msg.data.data[i].image + '"></td>';
                            html += '<td>' + msg.data.data[i].problem + '</td>';
							if(msg.data.data[i].pic == null){
								html += '<td>没有上传文件</td>';
							}else{
								html += '<td><a target="_blank" href="{:url('api/orders/download')}?id='+msg.data.data[i].id+'&type=1"  src="{:url('api/orders/download')}?id='+msg.data.data[i].id+'&type=1" class="download" style="cursor:pointer;">下载</a></td>';
							}
							html += '<td>' + msg.data.data[i].nick + '</td>';
                            html += '<td>' + msg.data.data[i].phone + '</td><td>' + ltime + '</td>';
                            if (msg.data.data[i].result == '' || msg.data.data[i].result == null) {
                                html += '<td class="result">暂无</td>';
                            } else {
                                html += '<td>' + msg.data.data[i].result + '</td>';
                            }
                            if (msg.data.data[i].static == 1) {
                                html += '<td class="td-status">未受理</td><td class="buttons td-manage">' +
                                    '<a class="btn table-btn" onclick="dispose(this)" href="#" title="处理问题"><i class="fa fa-check"></i></a>';
                            } else if (msg.data.data[i].static == 2) {
                                html += '<td class="td-status enable">待受理</td><td class="buttons td-manage">' +
                                    '<a class="btn table-btn replay—btn" onclick="replay_msg(this)" href="#" title="回复处理结果"><i class="fa fa fa-comment-o"></i></a>';
                            } else if (msg.data.data[i].static == 3) {
								if(msg.data.data[i].type != 2){
								    html += '<td class="td-status pass">已受理</td><td class="buttons td-manage">' +
                                    '<a class="btn table-btn replay—btn" onclick="refund_msg(this)" href="#" title="更改为待退款状态"><i class="fa fa fa-times"></i></a>';
								}

                             } else {
                                html += '<td class="td-status pass">已受理</td><td class="buttons td-manage">';
                            }
                            html += '<a class="btn table-btn" onclick="complain_msg(this)" href="#" title="查看详情"><i class="fa fa-ellipsis-h"></i></a></td></tr>';
                            $(".table tbody").append(html);
                        }
                    }
                    //分页
                    $(".table").attr("pages", page);
                    laypage({
                        cont: 'page',
                        pages: pages,
                        curr: page,
                        jump: function (obj, first) {
                            if (!first) { //点击跳页触发函数自身，并传递当前页：obj.curr
                                postfile(obj.curr);
                            }
                        }
                    })
					
                } else {
                    layer.msg('获取信息不成功!', {icon: 5, time: 2000});
                }
            }
        })
    }


	
    // 搜索
    $('#submit').click(function () {
        postfile(1);
    })

    //回车键绑定搜索
    $(".search-form").keydown(function (event) {
        if (event.keyCode == 13) {
            postfile(1);
        }
    });

    // 状态查询
    $("#select1").change(function () {
        postfile(1);
    });

    /*处理*/
    function dispose(obj) {
        var id = $(obj).parents("tr").attr('id');
        var page_id = $(".laypage_curr").html();
        layer.confirm('确认受理吗？', {
            btn: ['确认', '取消'] //按钮

        }, function () {
            $.ajax({
                type: 'GET',
                url: "{:url('api/complain/complain_dispose')}",
                dataType: 'jsonp',
                jsonp: 'callback',
                data: {id: id},
                success: function (msg) {
                    if (msg.code == 200) {
                        postfile(page_id);
                        $(obj).parents("tr").find(".td-status").html('待受理').addClass("enable");
                        $(obj).parents("tr").find(".td-manage").prepend('<a class="btn table-btn replay—btn" onclick="replay_msg(this)" href="#" title="回复处理结果"><i class="fa fa fa-comment-o"></i></a>');
                        $(obj).remove();
                        layer.msg('受理成功', {icon: 1, time: 1000});
                    } else {
                        layer.msg('受理失败', {icon: 5, time: 1000});
                    }
                }
            });
        }, function () {
            layer.closeAll();
        });
    }


    /*回复*/
    function replay_msg(obj) {
        layer.prompt({title: '回复消息', formType: 2}, function (text, index) {
            layer.close(index);
            var id = $(obj).parents("tr").attr('id');
            var page_id = $(".laypage_curr").html();
            $.ajax({
                type: 'GET',
                url: "{:url('api/complain/complain_replay')}",
                dataType: 'jsonp',
                jsonp: 'callback',
                data: {id: id, 'result': text},
                success: function (msg) {
                    if (msg.code == 200) {
                        $(obj).parents("tr").find(".td-status").html('受理完成').addClass("pass");
                        $(obj).parent().find('.replay—btn').remove();
                        $(obj).remove();
                        postfile(page_id);
                        layer.msg('已回复!', {icon: 1, time: 1000});
                    } else {
                        layer.msg('回复失败!', {icon: 5, time: 1000});
                    }
                }
            });
        })
    }


    //信息，查看详情
    function complain_msg(obj) {
        var id = "#" + $(obj).parents("tr").attr("id");
        layer.open({
            type: 2,
            title: '商品信息',
            shadeClose: true,
            shade: 0.8,
            area: ['700px', '700px'],
            content: 'complain_msg.html' + id
        })
        ;
    }

    //信息，查看详情
    function refund_msg(obj) {
        var id = $(obj).parents("tr").find('td.order').html();
        var page_id = $(".laypage_curr").html();
        layer.confirm('确认修改为退款状态吗？', {
            btn: ['确认', '取消'] //按钮
        }, function () {
            $.ajax({
                type: 'GET',
                url: "{:url('api/complain/complain_refund')}",
                dataType: 'jsonp',
                jsonp: 'callback',
                data: {id: id},
                success: function (msg) {
                    if (msg.code == 200) {
                        postfile(page_id);
                        layer.msg('已修改!', {icon: 1, time: 1000});
                    } else {
                        layer.msg('修改失败!', {icon: 5, time: 1000});
                    }
                }
            });
        });
    }

    //日期范围限制
    var start = {
        elem: '#logmin',
        format: 'YYYY-MM-DD',
        min: '1970-01-01', //设定最小日期为当前日期
        max: laydate.now(), //最大日期
        istime: false,
        istoday: false,
        choose: function (datas) {
            end.min = datas; //开始日选好后，重置结束日的最小日期
            end.start = datas //将结束日的初始值设定为开始日
        }
    };

    var end = {
        elem: '#logmax',
        format: 'YYYY-MM-DD',
        min: '1970-01-01',
        max: laydate.now(),
        istime: false,
        istoday: false,
        choose: function (datas) {
            start.max = datas; //结束日选好后，充值开始日的最大日期
        }
    };
    laydate(start);
    laydate(end);

</script>
</body>
</html>